/**
 * Created by BigBi on 2017/4/12.
 */
var http = require('http');
var url =  require('url');

function start(route){//将路由函数作为参数传递到 start 方法
    function httpRequest(request, response){
        var reqMethod = request.method;//请求的方法
        var pathname = url.parse(request.url).pathname;//请求的文件路径
        var query = url.parse(request.url).query;//请求的所有参数
        //querystring(string)["param1"]
        console.log("Request for " + pathname ,';request method is',reqMethod," received.The query is ",query);

        route(pathname);//调用方法 (在路由方法：即可以根据不同的请求，显示不同的页面)

        response.writeHead(200, {"Content-Type": "text/plain","charset":"UTF-8"});
        response.write("页面请求成功");
        response.end();
    }

    http.createServer(httpRequest).listen(8000,function(){
        console.log('serve is running on localhost:8000');
    });

}

exports.start=start;
